let date = new Date();


// 渲染每个月内容

let app = new Vue({
    el: '#app',
    data: {
        // 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
        days: [],
        weeks: ['一', '二', '三', '四', '五', '六', '日', ],
        day: 0,
        now: {
            year: 0,
            month: 0,
            day: 0,
            week: 0
        },
        date: ''
    },
    methods: {
        // 初始化当前日期
        init(year = this.getToday().year, month = this.getToday().month, day = 1) {
            // init(year = this.now.year, month = this.now.month, day = 1) {
            let date = new Date(year, month, day);
            this.now.year = date.getFullYear();
            this.now.month = date.getMonth() + 1;
            this.now.day = date.getDate(); //月中的某一天
            this.now.week = date.getDay(); //星期中的某一天
            this.renderCon(this.now.week);
        },
        // 跳转到上一个月
        lastMonth() {
            console.log('start');
            this.init(this.now.year, this.now.month - 1);
            this.renderCon(this.now.week);
        },
        nextMonth() {
            this.init(this.now.year, this.now.month + 1);
            this.renderCon(this.now.week);

        },
        renderCon(week) {
            if (this.now.week == 0) {
                this.now.week = '天'
            }
            this.date = `${this.now.year}年${this.now.month}月${this.now.day}日-星期${this.now.week}`
            switch (this.now.month) {
                case 2:
                    this.initday(28, week);
                    break;
                case 4:
                case 6:
                case 9:
                case 11:
                    this.initday(30, week);
                    break;
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                    this.initday(31, week);
                    break;
                default:
                    console.log("系统错误");
                    break;
            }
        },
        // 遍历天数
        initday(num, week) {
            console.log(this.now.week);
            for (var i = 0; i < num; i++) {
                this.days[i + week - 1] = i + 1;
            }
        },
        getToday() {
            // 获取今天月份
            let date = new Date();
            let now = {
                year: date.getFullYear(),
                month: date.getMonth(),
                day: date.getDate(), //月中的某一天
                week: date.getDay() //星期中的某一天
            }
            return now;
        },
        demo() {
            console.log(this.getToday().year);
            for (let i in this.getToday()) {
                console.log(this.getToday().i);
            }
        }

    },
    created() {
        this.init();

    }
})